import 'package:flutter/material.dart';

/// FileName single_child_list_view
///
/// @Author lax
/// @Date 2024/9/10
///
/// @Description

class SingleChildListView extends StatelessWidget {
  final bool showScrollbar;

  final bool shrinkWrap;

  final ScrollPhysics? physics;

  final EdgeInsets? padding;

  final Axis scrollDirection;

  final ScrollController? controller;

  final ScrollViewKeyboardDismissBehavior keyboardDismissBehavior;

  final Widget? child;

  const SingleChildListView({
    super.key,
    this.showScrollbar = true,
    this.shrinkWrap = false,
    this.padding,
    this.scrollDirection = Axis.vertical,
    this.controller,
    this.physics = const AlwaysScrollableScrollPhysics(),
    this.keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual,
    this.child,
  });

  @override
  Widget build(BuildContext context) {
    if (!showScrollbar) {
      return listView();
    }
    return Scrollbar(child: listView());
  }

  Widget listView() {
    return ListView(
      shrinkWrap: shrinkWrap,
      padding: padding ?? EdgeInsets.zero,
      scrollDirection: scrollDirection,
      controller: controller,
      physics: physics,
      keyboardDismissBehavior: keyboardDismissBehavior,
      children: child == null ? [] : [child!],
    );
  }
}
